﻿using Little.Soldier;
using Little.Soldier.SWIFT.Validation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Little.Soldier.SWIFT
{
  [ToolboxItem(false)]
  [DesignTimeVisible(false)]
  [TypeConverter(typeof (IMessageInputReference))]
  [Serializable]
  public class MessageInputReference
  {
    private string _InputDate;
    private string _LTAddress;
    private string _SequenceNumber;
    private string _SessionNumber;

    public virtual string InputDate
    {
      get
      {
        return this._InputDate;
      }
      set
      {
        this._InputDate = value;
      }
    }

    public virtual string LTAddress
    {
      get
      {
        return this._LTAddress;
      }
      set
      {
        this._LTAddress = value;
      }
    }

    public virtual string SequenceNumber
    {
      get
      {
        return this._SequenceNumber;
      }
      set
      {
        this._SequenceNumber = value;
      }
    }

    public virtual string SessionNumber
    {
      get
      {
        return this._SessionNumber;
      }
      set
      {
        this._SessionNumber = value;
      }
    }

    public MessageInputReference()
    {
    }

    public MessageInputReference(string inputDate, string lTAddress, string MIRSessionNumber, string MIRSequenceNumber)
    {
      this.InputDate = inputDate;
      this.LTAddress = lTAddress;
      this.SessionNumber = MIRSessionNumber;
      this.SequenceNumber = MIRSequenceNumber;
    }

    public virtual string GetValue()
    {
      switch (this.InputDate)
      {
        case null:
          if (this.LTAddress == null && (this.SessionNumber == null && this.SequenceNumber == null))
            return (string) null;
          else
            break;
      }
      StringBuilder stringBuilder = new StringBuilder();
      if (this.InputDate != null)
        stringBuilder.Append(this.InputDate);
      if (this.LTAddress != null)
        stringBuilder.Append(this.LTAddress);
      if (this.SessionNumber != null)
        stringBuilder.Append(this.SessionNumber);
      if (this.SequenceNumber != null)
        stringBuilder.Append(this.SequenceNumber);
      return ((object) stringBuilder).ToString();
    }

    public virtual bool SetValue(string value, List<ValidationError> parseError)
    {
      bool flag = true;
      switch (value)
      {
        case null:
          value = string.Empty;
          break;
      }
      if (value.Length != 28)
      {
        if (parseError != null)
        {
          ValidationError validationError = new ValidationError(ValidationErrorType.UsupportedBlockFormat, ((object) new StringBuilder().Append("expected a 28 characters string for MIR Value and found a ").Append(value.Length).Append(" string:").Append(value)).ToString());
          parseError.Add(validationError);
        }
        flag = false;
      }
      else
      {
        StringBuilder stringBuilder = new StringBuilder(value);
        int startIndex1 = 0;
        int length1 = 6;
        this.InputDate = ((object) stringBuilder).ToString().Substring(startIndex1, length1);
        int startIndex2 = startIndex1 + length1;
        int length2 = 12;
        this.LTAddress = ((object) stringBuilder).ToString().Substring(startIndex2, length2);
        int startIndex3 = startIndex2 + length2;
        int length3 = 4;
        this.SessionNumber = ((object) stringBuilder).ToString().Substring(startIndex3, length3);
        int startIndex4 = startIndex3 + length3;
        int length4 = 6;
        this.SequenceNumber = ((object) stringBuilder).ToString().Substring(startIndex4, length4);
        int num = startIndex4 + length4;
      }
      return flag;
    }
  }
}
